# poetry api
import logging
from fastapi import APIRouter, Query

from app.controllers import poetry_controller
from app.schemas.base import Success
from app.schemas.poetry import PoetryUpdate, PoetryCreate
from typing import List

logger = logging.getLogger(__name__)
router = APIRouter()


@router.post("/create", summary="创建诗词")
async def create_poetry(poetry_in: PoetryCreate):
    await poetry_controller.create(obj_in=poetry_in)
    return Success(message="添加成功")


@router.post("/create_bulk", summary="批量创建诗词")
async def create_poetry_bulk(poetry_list: List[PoetryCreate]):
    await poetry_controller.create_bulk(obj_list=poetry_list)
    return Success(message="批量添加成功")


@router.post("/update", summary="更新诗词")
async def update_poetry(poetry_in: PoetryUpdate):
    # 更新当前类别
    await poetry_controller.update(id=poetry_in.id, obj_in=poetry_in)
    return Success(message="修改成功")


@router.delete("/delete", summary="删除诗词")
async def delete_poetry(poetry_id: int = Query(..., description="类别ID")):
    await poetry_controller.remove(id=poetry_id)
    return Success(message="删除成功")
